package handler;

import entity.AdoptAnimal;
import entity.Pet;
import entity.User;
import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.Date;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;



public class AdoptListHandler implements ResultSetHandler<List<AdoptAnimal>> {
    @Override
    public List<AdoptAnimal> handle(ResultSet resultSet) throws SQLException {
        List<AdoptAnimal> adoptAnimalList = new ArrayList<>();
        while (resultSet.next()) {
            User user = new User();
            user.setId(resultSet.getInt("user.id"));
            user.setUserName(resultSet.getString("user.userName"));


            Pet pet = new Pet();
            pet.setId(resultSet.getInt("pet.id"));
            pet.setPetName(resultSet.getString("pet.petName"));
            pet.setState(resultSet.getInt("pet.state"));

            AdoptAnimal adoptAnimal = new AdoptAnimal();
            adoptAnimal.setId(resultSet.getInt("id"));
            adoptAnimal.setAdoptTime(resultSet.getDate("adoptTime"));
            adoptAnimal.setState(resultSet.getInt("state"));
            adoptAnimal.setUser(user);
            adoptAnimal.setPet(pet);
            adoptAnimalList.add(adoptAnimal);
        }
        return adoptAnimalList;
    }


}